package comits.web.client.servlets.demo;

import java.io.IOException;
import java.rmi.RemoteException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import comits.business.tiers.requests.clients.Comits_RP_TasksStub;
import comits.business.tiers.requests.clients.Comits_RP_TasksStub.EffectuerCalculBoutique;
import comits.business.tiers.requests.clients.Comits_RP_TasksStub.EffectuerCalculBoutiqueResponse;
import comits.business.tiers.requests.clients.Comits_RP_TasksStub.Encours;

/**
 * Servlet implementation class LoginServlet
 */
//@WebServlet("/LoginServlet")
public class ComitsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public ComitsServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		HttpSession session = request.getSession(true);
		
		if (request.getParameter("choix").equalsIgnoreCase("Voir infos du r�seau")){
			
		}else if (request.getParameter("choix").equalsIgnoreCase("Lancer le calcul")){
			
			try {
				Comits_RP_TasksStub stub = new Comits_RP_TasksStub();
				EffectuerCalculBoutique req = new EffectuerCalculBoutique();
				//req.setQuestion(question);
				try {
					EffectuerCalculBoutiqueResponse r = stub.effectuerCalculBoutique(req);
					Encours[] L_encours ;
					L_encours = r.get_return();
					session.setAttribute("listEncours",L_encours);
					
				} catch (RemoteException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} catch (AxisFault e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			RequestDispatcher dispatcher = request
			.getRequestDispatcher("afficherEncours.jsp");
	dispatcher.forward(request, response);
			
			
		/*	Fonctions f = new Fonctions();
		HttpSession session = request.getSession(true);
		try {
			System.out.println("debut servlet gestion composant");
			session.setAttribute("listComposant", f.getListComposantS());
			System.out.println( f.getListComposantS());
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		RequestDispatcher dispatcher = request
				.getRequestDispatcher("gestionComposant.jsp");
		dispatcher.forward(request, response);
		
		try {
				Comits_RP_TasksStub stub = new Comits_RP_TasksStub();
				EffectuerCalculBoutique req = new EffectuerCalculBoutique();
				try{
					EffectuerCalculBoutiqueResponse r = stub.effectuerCalculBoutique(req);
					return r.get_return()
					
				} catch (RemoteException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} catch (AxisFault e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}*/
		}
	}

}
